package com.hedl.practice.diyJava.enumeration;

import com.hedl.practice.diyJava.enumeration.utils.Color;
import com.hedl.practice.diyJava.enumeration.utils.Weekday;

public class Main {
    public static void main(String[] args) {
        //Weekday day = Weekday.SUN;        错误
        //int weekday = 0;

        /*if (Weekday.SUN == weekday){
            System.out.println("相等");
        }else {
            System.out.println("不想等");
        }*/

       /* String color = "r";

        if(Color.RED.equals(color)){
            System.out.println("相等");
        }else {
            System.out.println("不想等");
        }*/

/*
        //配合下面的enum类来使用
        Weekdat day = Weekdat.SUN;
        if (day == Weekdat.SAT || day == Weekdat.SUN){      //或：只要有一个对的就全是对的
            System.out.println("work at home!");
        }else {
            System.out.println("work at office!");
        }*/

        //enum类是可以使用等号的（==）或者equals;但是引用类型最好不要使用==号做比较；


        /*String s = Weekdat.SUN.name();       //返回元素的本身
        int s1 = Weekdat.MON.ordinal();     //查看enum类中的元素的位置
        System.out.println(s);
        System.out.println(s1);*/

       /* Weekdat day = Weekdat.SUN;
        if (day.dayValue == 6 || day.dayValue == 0){
            System.out.println("Today is "+ day +" Work at home!");
        }else {
            System.out.println("Today is "+ day +" Work at office!");
        }*/


        Weekdat day = Weekdat.SUN;
        switch(day){
            case MON:
            case TUE:
            case WED:
            case THU:
            case FRI:
                System.out.println("Today is "+ day +" Work at office!");
                break;
            case SAT:
            case SUN:
                System.out.println("Today is "+ day +" Work at home!");
                break;
            default:    //default语句，可以在漏写某个枚举常量时自动报错，从而及时发现错误。
                throw new RuntimeException("cannot process "+day);
        }

    }
}


/**
 *enum的特点：
 *  定义的enum类型总是继承自java.lang.Enum，且无法被继承；
 *  只能定义出enum的实例，而无法通过new操作符创建enum的实例；
 *  定义的每个实例都是引用类型的唯一实例；
 *  可以将enum类型用于switch语句。
 */
enum Weekdat{
    SUN,MON,TUE,WED,THU,FRI,SAT;

    /*MON(1,"星期一"),TUE(2,"星期二"),WED(3,"星期三"),THU(4,"星期四"),FRI(5,"星期五"),SAT(6,"星期六"),SUN(0,"星期日");

    public final int dayValue;
    private final String chinese;

    private Weekdat(int dayValue,String chinese){
        this.dayValue = dayValue;
        this.chinese = chinese;
    }

    //toString()的目的是在输出时更有可读性。
    public String toString(){
        return this.chinese;
    }*/
}
